package com.qinglei.recoup.system.controller;

import com.qinglei.recoup.common.domain.CommonRes;
import com.qinglei.recoup.hmp.pojo.vo.healthReport.HealthReportDayVo;
import com.qinglei.recoup.system.domain.BedHealthDailyStatistics;
import com.qinglei.recoup.system.domain.BedHealthQO;
import com.qinglei.recoup.system.domain.BedHealthShareParam;
import com.qinglei.recoup.system.pojo.SleepReportMoreVO;
import com.qinglei.recoup.system.pojo.SleepReportVO;
import com.qinglei.recoup.system.service.BedHealthDailyStatisticsService;
import com.qinglei.recoup.system.service.BedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;

@Api(tags = "H5开放接口控制器-石-已完成")
@Slf4j
@Validated
@RestController
@RequestMapping("h5/pub")
public class PublicController {
    @Resource
    private BedHealthDailyStatisticsService bedHealthDailyStatisticsService;

    @Resource
    private BedService bedService;

    @ApiOperation(value = "查询睡眠报告单天(二期)")
    @ApiImplicitParam(name = "code", value = "分享链接代码", paramType = "query", dataType = "String", required = true)
    @GetMapping("/oneDay")
    public CommonRes<SleepReportVO> getReportOne(String code) {
        SleepReportVO sleepReportOne = bedHealthDailyStatisticsService.getSleepReportOne4Share(code);
        return CommonRes.ok(sleepReportOne);
    }

    @ApiOperation(value = "查询睡眠报告多天(二期)")
    @ApiImplicitParam(name = "code", value = "分享链接代码", paramType = "query", dataType = "String", required = true)
    @GetMapping("/moreDay")
    public CommonRes<SleepReportMoreVO> getReportMore(String code) {
        SleepReportMoreVO reportMore = bedHealthDailyStatisticsService.getReportMore4Share(code);
        return CommonRes.ok(reportMore);
    }


    @ApiOperation(value = "查询睡眠报告单天(微信)")
    @GetMapping("/oneDayWx")
    public CommonRes getReportOneWx(BedHealthShareParam bedHealthShareParam) {
        Map<String,Object> resultMap = new HashMap<>();
        BedHealthDailyStatistics bedHealthDailyStatistics =   bedHealthDailyStatisticsService.selectBedHealthDailyStatistics(bedHealthShareParam);
        if(bedHealthDailyStatistics!=null && bedHealthDailyStatistics.getResultFlag()==0){
            //SleepReportVO sleepReportOne = bedHealthDailyStatisticsService.getSleepReportOne4ShareWx(bedHealthShareParam);
            BedHealthQO bedHealthQO = new BedHealthQO();
            bedHealthQO.setStartDate(LocalDate.parse(bedHealthShareParam.getStartDate()));
            bedHealthQO.setEndDate(LocalDate.parse(bedHealthShareParam.getEndDate()));
            bedHealthQO.setBedId(bedHealthShareParam.getBedId());
            SleepReportVO sleepReportOne = bedHealthDailyStatisticsService.getReportV4(bedHealthQO);
            resultMap.put("code",200);
            resultMap.put("data",sleepReportOne);
        }else {
            resultMap.put("code",500);
            resultMap.put("data",bedHealthDailyStatistics.getResultFlagStr());
        }
        return CommonRes.ok(resultMap);

    }

    @ApiOperation(value = "查询睡眠报告多天(二期)")
    @GetMapping("/moreDayWx")
    public CommonRes<SleepReportMoreVO> getReportMoreWx(BedHealthShareParam bedHealthShareParam) {
        SleepReportMoreVO reportMore = bedHealthDailyStatisticsService.getReportMore4ShareWx(bedHealthShareParam);
        return CommonRes.ok(reportMore);
    }



    @ApiOperation(value = "H5查询睡眠报告单天")
    @ApiImplicitParam(name = "code", value = "分享链接代码", paramType = "query", dataType = "String", required = true)
    @GetMapping("/getH5ReportOne")
    public CommonRes<HealthReportDayVo> getH5ReportOne(String code) {
        return bedHealthDailyStatisticsService.getH5SleepReportOneShare(code);
    }

}
